Python works with packages. A large number of packages can be dowloaded all together in the Anaconda environment. Start downloading here (version >3) https://www.anaconda.com/download/ Anaconda comes with
Enjoy!
Bee careful :
import warnings
warnings.filterwarnings('ignore')
print(1+2) # SUM #First operation and first comment
print(2*3) # MULTIPLICATION #Second operation and second comment
#Third comment
print(4/5) # DIVISION
print(3**4)# RAISE POWER
print((25/6-2*3)**2) # COMPLEXE OPERATION
print("Hello World")
my_integer = 54213
my_float = 21.514302
my_string = "Hello World"
print(my_integer)
print(my_float)
print(my_string)
print(my_integer > my_float)
print(my_integer != my_float)
print(my_integer == my_float)
print(my_integer < my_float)
print(my_integer != my_string)
print(my_integer == my_string)
# print(my_integer > my_string)
# print(my_integer < my_string)
Contain items separated by commas and enclosed within square brackets $[]$.
Each element can be modified.
my_list = [54213,21.514302,"Hello World","EDO"]
my_second_list = ["Ecole","Sante",2018,"EDO"]
print(my_list)
print(my_list[0])
print(my_list[1:3])
print(my_list[2:])
print(my_second_list*2)
print(my_list + my_second_list)
my_third_list = my_list[2:]
my_third_list[1] = "On change le deuxième élément"
print(my_third_list)
Contain items separated by commas and enclosed within square brackets $()$.
NO element can be modified.
my_tuple = (54213,21.514302,"Hello World","EDO")
my_second_tuple = ("Ecole","Sante",2018,"EDO")
print(my_tuple)
print(my_tuple[0])
print(my_tuple[1:3])
print(my_tuple[2:])
print(my_second_tuple*2)
print(my_tuple + my_second_tuple)
my_third_tuple = my_tuple[2:]
# my_third_tuple[1] = "On change le deuxième élément" # --> A tester... erreur!
print(my_third_tuple)
Works on the principle of key-value.
Dictionaries are enclosed by curly braces ${ }$ and values can be assigned and accessed using square braces $[]$.
my_dict = {}
my_dict['one'] = "un en inglish"
my_dict[2] = "deux"
my_second_dict = {'nom': 'hadrien','age':28, 'taille':1.94}
print(my_dict['one'])
print(my_dict[2])
print(my_second_dict)
print(my_second_dict.keys())
print(my_second_dict.values())
One acceses to strings values directly using using square braces $[]$.
my_string = "Hello Le Monde"
my_second_string = "Comment ca va ?"
print(my_second_string[0:7] + " donc" + my_second_string[10:14] + my_string[6:14] + my_second_string[-1])
Very practical to generate automatic personnalized titles in figures.
print("My name is %s and my weight is %d kg! My father's weight is %d kg but he is older than me!" % ('Zara', 21,95))
The notation is range(starting value, end value+1, step). The step parameter is optionnal.
my_list = list(range(1,10,1))
print(my_list)
# print(math.exp(my_list)) # --> Mais on ne peut pas faire grand chose dessus...
my_list_2 = [x * 0.1 for x in range(0, 10)]
print(my_list_2) # Super on a des floats
# print(math.exp(my_list_2)) # --> Mais ca n'est pas beaucoup mieux
numpy has been thought to deal with data generic operations.
import numpy as np
linspace uses the third argument to specify the number of points. The fourth argument "endpoint=True/False" permits to activate, or not, the right endpoint.
my_np_linspace = np.linspace(0.,1.,11)
print(my_np_linspace)
print(np.exp(my_np_linspace))
arange permits to specify the step
my_np_arange = np.arange(0.0, 1.0, 0.1)
print(my_np_arange)
print(np.exp(my_np_arange))
... Find the other over-exciting mathematical functions from numpy.
import matplotlib.pyplot as plt
fig = plt.figure()
plt.plot(my_np_arange,np.exp(my_np_arange), color='green', marker='o', linestyle='dashed',linewidth=2, markersize=12)
fig.suptitle('Une belle exponentielle', fontsize=20)
plt.xlabel('x ensemble de départ', fontsize=18)
plt.ylabel('y ensemble d arrivee', fontsize=16)